#pragma once
#include "TCharSupport.h"
#include <list>
#include "EpilOperator.h"

using namespace std;


class EpilOutputHelper
{
public:
	static tstring						GetIndent( int indent );
	static tstring						GetUnaryOperator( EpilUnaryOperator op );
	static tstring						GetBinaryOperator( EpilBinaryOperator op );
	static int							GetUnaryOperatorPrecedence( EpilUnaryOperator op );
	static int							GetBinaryOperatorPrecedence( EpilBinaryOperator op );

										template<typename T>
	static tstring						GetListOutput( const list<T> & codes, const tstring & delimeter );
										template<>
	static tstring						GetListOutput( const list<tstring> & codes, const tstring & delimeter );
										template<typename T>
	static tstring						GetListOutputIndent( const list<T> & codes, const tstring & delimeter, int indent );
};


template<typename T>
tstring EpilOutputHelper::GetListOutput( const list<T> & codes, const tstring & delimeter )
{
	tstringstream ret;
	ret << (*codes.begin())->ToEpilCode();
	
	list<T>::const_iterator it = codes.begin();
	++it;
	for( ; it != codes.end(); ++it )
	{
		ret << delimeter;
		ret << (*it)->ToEpilCode();
	}

	return ret.str();
}


template<>
tstring EpilOutputHelper::GetListOutput( const list<tstring> & codes, const tstring & delimeter )
{
	tstringstream ret;
	ret << *codes.begin();
	
	list<tstring>::const_iterator it = codes.begin();
	++it;
	for( ; it != codes.end(); ++it )
	{
		ret << delimeter;
		ret << *it;
	}

	return ret.str();
}


template<typename T>
tstring EpilOutputHelper::GetListOutputIndent( const list<T> & codes, const tstring & delimeter, int indent )
{
	tstringstream ret;
	ret << (*codes.begin())->ToEpilCode( indent );
	
	list<T>::const_iterator it = codes.begin();
	++it;
	for( ; it != codes.end(); ++it )
	{
		ret << delimeter;
		ret << (*it)->ToEpilCode( indent );
	}

	return ret.str();
}